package cn.edu.cxcyzx.supervisor;

import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;
import org.springframework.stereotype.Component;

import cn.edu.cxcyzx.util.UploadStatus;

@Component
public class UploadListener implements ProgressListener {
	
	private HttpSession httpSession;
	
	public void setSession(HttpSession httpSession){
		this.setSession(httpSession);
		UploadStatus uploadStatus=new UploadStatus();
		httpSession.setAttribute("uploadStatus", uploadStatus);
	}
	
	
	
	@Override
	public void update(long bytesRead, long contentLength, int items) {
		// TODO Auto-generated method stub
		//参数byteRead表示已经上传的字节数，contentLength表示上传的总长度（如果为-1则表示总长度未知），
		//items表示正在上传第几个文件
		UploadStatus uploadStatus=(UploadStatus) httpSession.getAttribute("uploadStatus");
		uploadStatus.setBytesRead(bytesRead);
		uploadStatus.setContentLength(contentLength);
		uploadStatus.setItems(items);
		
	}

}
